package Common 
{
	import Box2D.Collision.Shapes.b2PolygonShape;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2BodyDef;
	import Box2D.Dynamics.b2FixtureDef;
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import Game.GameStates.GameState;
	/**
	 * ...
	 * @author Yevgeniy Logachev
	 */
	public class Utils 
	{
		
		public function Utils() 
		{
			
		}
		
		// Recursive function. Stop all nested animation in MovieClip
		public static function stopAll(animation:Sprite):void
		{
			if (animation != null)
			{
				if(animation is MovieClip)
				{
					(animation as MovieClip).stop();
				}
				for(var i:int = 0; i < animation.numChildren; ++i)
				{
					var child:Sprite = animation.getChildAt(i) as Sprite;
					if (child != null)
					{
						stopAll(child);
					}
				}
			}
		}
		
		// Recursive function. Play all nested animation in MovieClip
		public static function playAll(animation:Sprite):void
		{
			if (animation != null)
			{
				if(animation is MovieClip)
				{
					(animation as MovieClip).play();
				}
				for(var i:int = 0; i < animation.numChildren; ++i)
				{
					var child:Sprite = animation.getChildAt(i) as Sprite;
					if (child != null)
					{
						playAll(child);
					}
				}
			}
		}
		
		public static function getDirection(object:DisplayObject):b2Vec2
		{
			return new b2Vec2(object.transform.matrix.a, object.transform.matrix.b);
		}
		
		public static function getDirectionRotate(angle1:Number, angle2:Number):Number
		{
			if (angle1 >= angle2)
			{
				if ((angle1 - angle2) > 180) 
				{	
					return 359 - angle1 + angle2; // 1
				}
				else 
				{
					return angle2 - angle1; // -1
				}
			}
			else
			{
				if ((angle2 - angle1) > 180) 
				{
					return angle2 - 359 - angle1; // -1
				}
				else 
				{
					return angle2 - angle1; // 1
				}
			}
		}
		
		public static function sign(value:Number):int
		{
			if (value > 0) return 1;
			else if (value < 0) return -1;
			
			return 0;
		}
	}

}